package co.edu.usbcali.sap.presentation.backEndBeans;

import co.edu.usbcali.sap.exceptions.*;
import co.edu.usbcali.sap.modelo.*;
import co.edu.usbcali.sap.modelo.dto.PersonaDTO;
import co.edu.usbcali.sap.presentation.businessDelegate.BusinessDelegatorView;
import co.edu.usbcali.sap.utilities.*;

import com.icesoft.faces.async.render.RenderManager;
import com.icesoft.faces.async.render.Renderable;
import com.icesoft.faces.component.ext.HtmlCommandButton;
import com.icesoft.faces.component.ext.HtmlInputSecret;
import com.icesoft.faces.component.ext.HtmlInputText;

import com.icesoft.faces.component.ext.HtmlSelectOneMenu;

import com.icesoft.faces.context.DisposableBean;
import com.icesoft.faces.webapp.xmlhttp.FatalRenderingException;
import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
import com.icesoft.faces.webapp.xmlhttp.RenderingException;
import com.icesoft.faces.webapp.xmlhttp.TransientRenderingException;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.Vector;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.DataModel;
import javax.faces.model.SelectItem;

/**
 * 
 * 
 * @author Zathura Code Generator http://code.google.com/p/zathura
 * 
 */
public class PersonaView extends DataSource implements Renderable,
		DisposableBean {
	// //////////hechos/////////////
	private HtmlSelectOneMenu cmbRol;
	private List<SelectItem> listaRol = new ArrayList<SelectItem>();
	private HtmlInputSecret txtRolpasw;
	private HtmlInputSecret txtRolpasw1;

	private HtmlInputSecret txtpass;

	// /////////generados///////////
	private HtmlInputText txtPerCedula;
	private HtmlInputText txtPerDireccion;
	private HtmlInputText txtPerEmail;
	private HtmlInputText txtPerNombre;
	private HtmlInputText txtPerTelefono;
	private HtmlInputText txtPerCodigo;
	private HtmlCommandButton btnSave;
	private HtmlCommandButton btnModify;
	private HtmlCommandButton btnDelete;
	private HtmlCommandButton btnClear;
	private boolean renderDataTable;
	private boolean flag = true;
	private RenderManager renderManager;
	private PersistentFacesState state = PersistentFacesState.getInstance();
	private List<Persona> persona;
	private List<PersonaDTO> personaDTO;

	// ///////////////////////////////////////////////////////////////////////////////////////
	public PersonaView() {
		super("");
	}

	public String action_clear() {
		txtPerCedula.setValue(null);
		txtPerCedula.setDisabled(true);
		txtPerDireccion.setValue(null);
		txtPerDireccion.setDisabled(true);
		txtPerEmail.setValue(null);
		txtPerEmail.setDisabled(true);
		txtPerNombre.setValue(null);
		txtPerNombre.setDisabled(true);
		txtPerTelefono.setValue(null);
		txtPerTelefono.setDisabled(true);
		txtPerCodigo.setValue(null);
		txtPerCodigo.setDisabled(false);
		btnSave.setDisabled(true);
		btnDelete.setDisabled(true);
		btnModify.setDisabled(true);
		btnClear.setDisabled(false);

		txtRolpasw.setValue(null);
		txtRolpasw.setDisabled(true);
		txtRolpasw1.setValue(null);
		txtRolpasw1.setDisabled(true);
		listaRol.clear();
		cmbRol.setValue(null);
		cmbRol.setDisabled(true);

		return "";
	}

	public void listener_txtId(ValueChangeEvent event) {
		// /borro los roles para volverlos a cargar
		// listaRol.clear();

		if ((event.getNewValue() != null) && !event.getNewValue().equals("")) {
			Persona entity = null;

			try {
				Integer perCodigo = new Integer(txtPerCodigo.getValue()
						.toString());
				entity = BusinessDelegatorView.getPersona(perCodigo);
				/*
				 * // ///////// llenado de el combo de rol en la jspx persona
				 * SelectItem item = new SelectItem(0, "Seleccione un Rol");
				 * listaRol.add(item); for (Rol rol :
				 * BusinessDelegatorView.getRol()) { if(listaRol.size()<4){ item
				 * = new SelectItem(rol.getRolCodigo(), rol .getRolNombre());
				 * listaRol.add(item); }else { + break; }
				 */// }

			} catch (Exception e) {
				// TODO: handle exception
			}

			if (entity == null) {
				txtPerCedula.setDisabled(false);
				txtPerDireccion.setDisabled(false);
				txtPerEmail.setDisabled(false);
				txtPerNombre.setDisabled(false);
				txtPerTelefono.setDisabled(false);
				txtPerCodigo.setDisabled(false);
				btnSave.setDisabled(false);
				btnDelete.setDisabled(true);
				btnModify.setDisabled(true);
				btnClear.setDisabled(false);

				txtRolpasw.setDisabled(false);
				txtRolpasw1.setDisabled(false);
				cmbRol.setDisabled(false);
			} else {

				txtPerCedula.setValue(entity.getPerCedula());
				txtPerDireccion.setValue(entity.getPerDireccion());
				txtPerEmail.setValue(entity.getPerEmail());
				txtPerNombre.setValue(entity.getPerNombre());
				txtPerTelefono.setValue(entity.getPerTelefono());
				txtPerCodigo.setValue(entity.getPerCodigo());
				txtPerCodigo.setDisabled(true);
				btnSave.setDisabled(true);
				btnModify.setDisabled(false);
				btnClear.setDisabled(false);
				txtRolpasw.setValue(entity.getPerContrasena() + "");
				System.out.println(entity.getPerContrasena());
				txtRolpasw1.setValue(entity.getPerContrasena());
				cmbRol.setValue(entity.getRol().getRolCodigo());
				if (entity.getPerEstado().equals("activo")) {
					txtPerCedula.setDisabled(false);
					txtPerDireccion.setDisabled(false);
					txtPerEmail.setDisabled(false);
					txtPerNombre.setDisabled(false);
					txtPerTelefono.setDisabled(false);					
					btnDelete.setDisabled(false);
					txtRolpasw.setDisabled(false);
					txtRolpasw1.setDisabled(false);
					cmbRol.setDisabled(false);
				}else {
					FacesContext.getCurrentInstance().addMessage("",
							new FacesMessage("El Usuario se encuentra inactivo, presione modificar para activar de nuevo"));
				}
					

			}
		}
	}

	public String action_save() {

		try {

			String codigo = txtPerCodigo.getValue().toString();
			String cedula = txtPerCedula.getValue().toString();
			String nombre = txtPerNombre.getValue().toString();
			String pas1 = txtRolpasw.getValue().toString();
			String pass2 = txtRolpasw1.getValue().toString();
			String direccion = txtPerDireccion.getValue().toString();
			String telefono = txtPerTelefono.getValue().toString();
			String email = txtPerEmail.getValue().toString();

			if (codigo.equals("")) {
				throw new Exception(
						"El c&#243;digo de la persona  es de caracter obligatorio");
			}

			if (Utilities.soloNumeros(codigo) == false) {
				throw new Exception(
						"El c&#243;digo de la persona no acepta letras ni caracteres especiales como @#$%^&*()");
			}

			if (cedula.equals("")) {
				throw new Exception(
						"La c&#233;dula de la persona es de caracter obligatorio");
			}

			if (Utilities.soloNumeros(cedula) == false) {
				throw new Exception(
						"La c&#233;dula de la persona no permite letras ni caracteres especiales como @#$%^&*()");
			}

			if (nombre.equals("")) {
				throw new Exception(
						"el nombre de la persona es de caracter obligatorio");
			}

			if (Utilities.soloLetras(nombre) == false) {
				throw new Exception(
						"El nombre no permite n&#250;meros ni caracteres especiales como @#$%^&*()");
			}

			if (!pas1.equals(pass2)) {
				throw new Exception("Las contrase&#241;as no coinciden");
			}

			if (direccion.equals("")) {
				throw new Exception("La direcci&#243;n es obligatoria");
			}

			if (telefono.equals("")) {
				throw new Exception(
						"El tel&#233;fono es de caracter obligatorio");
			}

			if (Utilities.soloNumeros(telefono) == false) {
				throw new Exception(
						"El tel&#233;fono no acepta letras ni caracteres especiales como @#$%^&*()");
			}

			if (email.equals("")) {
				throw new Exception("El email es de caracter obligatorio");
			}

			if (Utilities.correElectronico(email) == false) {
				throw new Exception(
						"El email no tiene un formato v&#225;lido asegurece de que cumpla el siguiente formato xxx@xxx.com");
			}

			BusinessDelegatorView.savePersona(new Long(cedula), new Integer(
					codigo), txtRolpasw.getValue().toString(), txtPerDireccion
					.getValue().toString(), txtPerEmail.getValue().toString(),
					txtPerNombre.getValue().toString(), new Long(telefono),
					new Integer(cmbRol.getValue().toString()));
			FacesContext.getCurrentInstance().addMessage("",
					new FacesMessage("Se creo la persona con &#233;xito"));

			/*
			 * BusinessDelegatorView
			 * .savePersona(FacesUtils.checkLong(txtPerCedula), FacesUtils
			 * .checkInteger(txtPerCodigo), FacesUtils .checkString(txtRolpasw),
			 * FacesUtils .checkString(txtPerDireccion), FacesUtils
			 * .checkEmail(txtPerEmail), FacesUtils .checkString(txtPerNombre),
			 * FacesUtils .checkLong(txtPerTelefono), FacesUtils
			 * .checkInteger(cmbRol));
			 */// FacesUtils.addInfoMessage(ZMessManager.ENTITY_SUCCESFULLYSAVED);

			action_clear();
		} catch (Exception e) {
			FacesContext.getCurrentInstance().addMessage("",
					new FacesMessage(e.getMessage()));
		}

		return "";

	}

	public String action_delete() {
		try {
			BusinessDelegatorView.deletePersona(FacesUtils
					.checkInteger(txtPerCodigo));
			FacesUtils.addInfoMessage(ZMessManager.ENTITY_SUCCESFULLYDELETED);
			action_clear();
		} catch (Exception e) {
			FacesUtils.addErrorMessage(e.getMessage());
		}

		return "";
	}

	public String action_modify() {

		try {

			String codigo = txtPerCodigo.getValue().toString();
			String cedula = txtPerCedula.getValue().toString();
			String nombre = txtPerNombre.getValue().toString();
			String pas1 = txtRolpasw.getValue().toString();
			String pass2 = txtRolpasw1.getValue().toString();
			String direccion = txtPerDireccion.getValue().toString();
			String telefono = txtPerTelefono.getValue().toString();
			String email = txtPerEmail.getValue().toString();

			if (codigo.equals("")) {
				throw new Exception(
						"El c&#243;digo de la persona  es de caracter obligatorio");
			}

			if (Utilities.soloNumeros(codigo) == false) {
				throw new Exception(
						"El c&#243;digo de la persona no acepta letras ni caracteres especiales como @#$%^&*()");
			}

			if (cedula.equals("")) {
				throw new Exception(
						"La c&#233;dula de la persona es de caracter obligatorio");
			}

			if (Utilities.soloNumeros(cedula) == false) {
				throw new Exception(
						"La c&#233;dula de la persona no permite letras ni caracteres especiales como @#$%^&*()");
			}

			if (nombre.equals("")) {
				throw new Exception(
						"el nombre de la persona es de caracter obligatorio");
			}

			if (Utilities.soloLetras(nombre) == false) {
				throw new Exception(
						"El nombre no permite n&#250;meros ni caracteres especiales como @#$%^&*()");
			}

			if (!pas1.equals(pass2)) {
				throw new Exception("Las contraseñas no coinciden");
			}

			if (direccion.equals("")) {
				throw new Exception("La direcci&#243;n es obligatoria");
			}

			if (telefono.equals("")) {
				throw new Exception(
						"El tel&#233;fono es de caracter obligatorio");
			}

			if (Utilities.soloNumeros(telefono) == false) {
				throw new Exception(
						"El tel&#233;fono no acepta letras ni caracteres especiales como @#$%^&*()");
			}

			if (email.equals("")) {
				throw new Exception("El email es de caracter obligatorio");
			}

			if (Utilities.correElectronico(email) == false) {
				throw new Exception(
						"El email no tiene un formato v&#225;lido asegurece de que cumpla el siguiente formato xxx@xxx.com");
			}

			BusinessDelegatorView.updatePersona(new Long(cedula), new Integer(
					codigo), txtRolpasw.getValue().toString(), txtPerDireccion
					.getValue().toString(), txtPerEmail.getValue().toString(),
					txtPerNombre.getValue().toString(), new Long(telefono),
					new Integer(cmbRol.getValue().toString()));
			FacesContext.getCurrentInstance().addMessage(
					"",
					new FacesMessage(
							"Se modific&#243; el registro con &#233;xito"));
			action_clear();
		} catch (Exception e) {
			FacesContext.getCurrentInstance().addMessage("",
					new FacesMessage(e.getMessage()));
		}

		return "";
	}

	public String action_modifyWitDTO(Long perCedula, Integer perCodigo,
			String pass, String perDireccion, String perEmail,
			String perNombre, Long perTelefono, Integer rol) throws Exception {
		try {
			BusinessDelegatorView.updatePersona(perCedula, perCodigo, pass,
					perDireccion, perEmail, perNombre, perTelefono, rol);
			renderManager.getOnDemandRenderer("PersonaView").requestRender();
			FacesUtils.addInfoMessage(ZMessManager.ENTITY_SUCCESFULLYMODIFIED);
		} catch (Exception e) {
			// renderManager.getOnDemandRenderer("PersonaView").requestRender();
			FacesUtils.addErrorMessage(e.getMessage());
			throw e;
		}

		return "";
	}

	public List<Persona> getPersona() {
		if (flag) {
			try {
				persona = BusinessDelegatorView.getPersona();
				flag = false;
			} catch (Exception e) {
				flag = true;
				FacesUtils.addErrorMessage(e.getMessage());
			}
		}

		return persona;
	}

	public boolean isFlag() {
		return flag;
	}

	public void setPersona(List<Persona> persona) {
		this.persona = persona;
	}

	public boolean isRenderDataTable() {
		try {
			if (flag) {
				if (BusinessDelegatorView.findTotalNumberPersona() > 0) {
					renderDataTable = true;
				} else {
					renderDataTable = false;
				}
			}

			flag = false;
		} catch (Exception e) {
			renderDataTable = false;
			e.printStackTrace();
		}

		return renderDataTable;
	}

	public DataModel getData() {
		state = PersistentFacesState.getInstance();

		if (onePageDataModel == null) {
			onePageDataModel = new LocalDataModel(pageSize);
		}

		return onePageDataModel;
	}

	/**
	 * This is where the Object data is retrieved from the database and returned
	 * as a list of objects for display in the UI.
	 */
	private DataPage<Persona> getDataPage(int startRow, int pageSize) {
		// Retrieve the total number of objects from the database. This
		// number is required by the DataPage object so the paginator will know
		// the relative location of the page data.
		int totalNumberPersona = 0;

		try {
			totalNumberPersona = BusinessDelegatorView.findTotalNumberPersona()
					.intValue();
		} catch (Exception e) {
			FacesUtils.addErrorMessage(e.getMessage());
		}

		// Calculate indices to be displayed in the ui.
		int endIndex = startRow + pageSize;

		if (endIndex > totalNumberPersona) {
			endIndex = totalNumberPersona;
		}

		try {
			persona = BusinessDelegatorView.findPagePersona(sortColumnName,
					sortAscending, startRow, endIndex - startRow);

			// Remove this Renderable from the existing render groups.
			// leaveRenderGroups();
		} catch (Exception e) {
			FacesUtils.addErrorMessage(e.getMessage());
		}

		// Add this Renderable to the new render groups.
		// joinRenderGroups();
		// Reset the dirtyData flag.
		onePageDataModel.setDirtyData(false);
		// This is required when using Hibernate. If the SessionManager is not
		// cleared or closed objects are cached and stale objects will show up
		// in the table.
		// This way, the detached objects are reread from the database.
		// This call is not required with Hibernate, which uses a Query Hint
		// to clear the l2 cache in the DAO.
		flag = true;

		return new DataPage<Persona>(totalNumberPersona, startRow, persona);
	}

	public DataModel getDataDTO() {
		state = PersistentFacesState.getInstance();

		if (onePageDataModel == null) {
			onePageDataModel = new LocalDataModelDTO(pageSize);
		}

		return onePageDataModel;
	}

	/**
	 * This is where the Object data is retrieved from the database and returned
	 * as a list of objects for display in the UI.
	 */
	private DataPage<PersonaDTO> getDataPageDTO(int startRow, int pageSize) {
		// Retrieve the total number of objects from the database. This
		// number is required by the DataPage object so the paginator will know
		// the relative location of the page data.
		int totalNumberPersona = 0;

		try {
			totalNumberPersona = BusinessDelegatorView.findTotalNumberPersona()
					.intValue();
		} catch (Exception e) {
			FacesUtils.addErrorMessage(e.getMessage());
		}

		// Calculate indices to be displayed in the ui.
		int endIndex = startRow + pageSize;

		if (endIndex > totalNumberPersona) {
			endIndex = totalNumberPersona;
		}

		try {
			persona = BusinessDelegatorView.findPagePersona(sortColumnName,
					sortAscending, startRow, endIndex - startRow);

			if (Utilities.validationsList(persona)) {
				personaDTO = new ArrayList<PersonaDTO>();

				for (Persona personaTmp : persona) {
					PersonaDTO personaDTO2 = new PersonaDTO();
					personaDTO2.setPerCodigo(personaTmp.getPerCodigo()
							.toString());
					personaDTO2
							.setPerCedula((personaTmp.getPerCedula() != null) ? personaTmp
									.getPerCedula().toString()
									: null);
					personaDTO2
							.setPerDireccion((personaTmp.getPerDireccion() != null) ? personaTmp
									.getPerDireccion().toString()
									: null);
					personaDTO2
							.setPerEmail((personaTmp.getPerEmail() != null) ? personaTmp
									.getPerEmail().toString()
									: null);
					personaDTO2
							.setPerNombre((personaTmp.getPerNombre() != null) ? personaTmp
									.getPerNombre().toString()
									: null);
					personaDTO2
							.setPerTelefono((personaTmp.getPerTelefono() != null) ? personaTmp
									.getPerTelefono().toString()
									: null);
					personaDTO2.setPersona(personaTmp);
					personaDTO2.setPersonaView(this);
					personaDTO.add(personaDTO2);
				}
			}

			// Remove this Renderable from the existing render groups.
			leaveRenderGroups();
		} catch (Exception e) {
			FacesUtils.addErrorMessage(e.getMessage());
		}

		// Add this Renderable to the new render groups.
		joinRenderGroups();
		// Reset the dirtyData flag.
		onePageDataModel.setDirtyData(false);
		// This is required when using Hibernate. If the SessionManager is not
		// cleared or closed objects are cached and stale objects will show up
		// in the table.
		// This way, the detached objects are reread from the database.
		// This call is not required with Hibernate, which uses a Query Hint
		// to clear the l2 cache in the DAO.
		flag = true;

		return new DataPage<PersonaDTO>(totalNumberPersona, startRow,
				personaDTO);
	}

	protected boolean isDefaultAscending(String sortColumn) {
		return true;
	}

	/**
	 * This method is called when a render call is made from the server. Render
	 * calls are only made to views containing an updated record. The data is
	 * marked as dirty to trigger a fetch of the updated record from the
	 * database before rendering takes place.
	 */
	public PersistentFacesState getState() {
		onePageDataModel.setDirtyData();

		return state;
	}

	/**
	 * This method is called from faces-config.xml with each new session.
	 */
	public void setRenderManager(RenderManager renderManager) {
		this.renderManager = renderManager;
	}

	public void renderingException(RenderingException arg0) {
		if (arg0 instanceof TransientRenderingException) {
		} else if (arg0 instanceof FatalRenderingException) {
			// Remove from existing Customer render groups.
			leaveRenderGroups();
		}
	}

	/**
	 * Remove this Renderable from existing uiCustomerBeans render groups.
	 * OnDemandRenderers are named/created using the underlying Customer Number.
	 */
	private void leaveRenderGroups() {
		if (Utilities.validationsList(personaDTO)) {
			for (PersonaDTO personaTmp : personaDTO) {
				renderManager.getOnDemandRenderer("PersonaView").remove(this);
			}
		}
	}

	/**
	 * Add this Renderable to the new uiCustomerBeans render groups.
	 * OnDemandRenderers are named/created using the underlying Customer Number.
	 */
	private void joinRenderGroups() {
		if (Utilities.validationsList(personaDTO)) {
			for (PersonaDTO personaTmp : personaDTO) {
				renderManager.getOnDemandRenderer("PersonaView").add(this);
			}
		}
	}

	// //////////get y set
	// hechos////////////////////////////////////////////////////////7
	public HtmlSelectOneMenu getCmbRol() {
		return cmbRol;
	}

	public void setCmbRol(HtmlSelectOneMenu cmbRol) {
		this.cmbRol = cmbRol;
	}

	public List<SelectItem> getListaRol() {

		try {

			List<Rol> allRoles = BusinessDelegatorView.getRol();
			List<SelectItem> rolesPersona = new ArrayList<SelectItem>();

			rolesPersona.add(new SelectItem(0, "Seleccione un Rol "));
			for (int i = 0; i < 3; i++) {
				SelectItem item = new SelectItem(
						allRoles.get(i).getRolCodigo(), allRoles.get(i)
								.getRolNombre());
				rolesPersona.add(item);
			}

			listaRol = rolesPersona;

		} catch (Exception e) {

		}

		return listaRol;
	}

	public void setListaRol(List<SelectItem> listaRol) {
		this.listaRol = listaRol;
	}

	public HtmlInputSecret getTxtRolpasw() {
		return txtRolpasw;
	}

	public void setTxtRolpasw(HtmlInputSecret txtRolpasw) {
		this.txtRolpasw = txtRolpasw;
	}

	public HtmlInputSecret getTxtRolpasw1() {
		return txtRolpasw1;
	}

	public void setTxtRolpasw1(HtmlInputSecret txtRolpasw1) {
		this.txtRolpasw1 = txtRolpasw1;
	}

	// //////////get y set
	// generados///////////////////////////////////////////////////////////7
	public void dispose() throws Exception {
	}

	public RenderManager getRenderManager() {
		return renderManager;
	}

	public void setState(PersistentFacesState state) {
		this.state = state;
	}

	public HtmlInputText getTxtPerCedula() {
		return txtPerCedula;
	}

	public void setTxtPerCedula(HtmlInputText txtPerCedula) {
		this.txtPerCedula = txtPerCedula;
	}

	public HtmlInputText getTxtPerDireccion() {
		return txtPerDireccion;
	}

	public void setTxtPerDireccion(HtmlInputText txtPerDireccion) {
		this.txtPerDireccion = txtPerDireccion;
	}

	public HtmlInputText getTxtPerEmail() {
		return txtPerEmail;
	}

	public void setTxtPerEmail(HtmlInputText txtPerEmail) {
		this.txtPerEmail = txtPerEmail;
	}

	public HtmlInputText getTxtPerNombre() {
		return txtPerNombre;
	}

	public void setTxtPerNombre(HtmlInputText txtPerNombre) {
		this.txtPerNombre = txtPerNombre;
	}

	public HtmlInputText getTxtPerTelefono() {
		return txtPerTelefono;
	}

	public void setTxtPerTelefono(HtmlInputText txtPerTelefono) {
		this.txtPerTelefono = txtPerTelefono;
	}

	public HtmlInputText getTxtPerCodigo() {
		return txtPerCodigo;
	}

	public void setTxtPerCodigo(HtmlInputText txtPerCodigo) {
		this.txtPerCodigo = txtPerCodigo;
	}

	public HtmlCommandButton getBtnSave() {
		return btnSave;
	}

	public void setBtnSave(HtmlCommandButton btnSave) {
		this.btnSave = btnSave;
	}

	public HtmlCommandButton getBtnModify() {
		return btnModify;
	}

	public void setBtnModify(HtmlCommandButton btnModify) {
		this.btnModify = btnModify;
	}

	public HtmlCommandButton getBtnDelete() {
		return btnDelete;
	}

	public void setBtnDelete(HtmlCommandButton btnDelete) {
		this.btnDelete = btnDelete;
	}

	public HtmlCommandButton getBtnClear() {
		return btnClear;
	}

	public void setBtnClear(HtmlCommandButton btnClear) {
		this.btnClear = btnClear;
	}

	public void setRenderDataTable(boolean renderDataTable) {
		this.renderDataTable = renderDataTable;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public List<PersonaDTO> getPersonaDTO() {
		return personaDTO;
	}

	public void setPersonaDTO(List<PersonaDTO> personaDTO) {
		this.personaDTO = personaDTO;
	}

	public TimeZone getTimeZone() {
		return java.util.TimeZone.getDefault();
	}

	public HtmlInputSecret getTxtpass() {
		return txtpass;
	}

	public void setTxtpass(HtmlInputSecret txtpass) {
		this.txtpass = txtpass;
	}

	/**
	 * A special type of JSF DataModel to allow a datatable and datapaginator to
	 * page through a large set of data without having to hold the entire set of
	 * data in memory at once. Any time a managed bean wants to avoid holding an
	 * entire dataset, the managed bean declares this inner class which extends
	 * PagedListDataModel and implements the fetchData method. fetchData is
	 * called as needed when the table requires data that isn't available in the
	 * current data page held by this object. This requires the managed bean
	 * (and in general the business method that the managed bean uses) to
	 * provide the data wrapped in a DataPage object that provides info on the
	 * full size of the dataset.
	 */
	private class LocalDataModel extends PagedListDataModel {
		public LocalDataModel(int pageSize) {
			super(pageSize);
		}

		public DataPage<Persona> fetchPage(int startRow, int pageSize) {
			// call enclosing managed bean method to fetch the data
			return getDataPage(startRow, pageSize);
		}
	}

	private class LocalDataModelDTO extends PagedListDataModel {
		public LocalDataModelDTO(int pageSize) {
			super(pageSize);
		}

		public DataPage<PersonaDTO> fetchPage(int startRow, int pageSize) {
			// call enclosing managed bean method to fetch the data
			return getDataPageDTO(startRow, pageSize);
		}
	}
}
